package com.acwing.partition11;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/3/6 9:42
 */
public class AC1047糖果 {

    private static final int N = 110;
    private static int[] w = new int[N];
    private static int[][] f = new int[N][N];
    private static int n, k;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        k = Integer.parseInt(ss[1]);
        for (int i = 1; i <= n; i++) w[i] = Integer.parseInt(reader.readLine());
        for (int i = 0; i < N; i++) Arrays.fill(f[i], -0x3f3f3f3f);
        f[0][0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                f[i][j] = Math.max(f[i - 1][j], f[i - 1][getMod(j - w[i], k)] + w[i]);
            }
        }
        writer.write(f[n][0] + "\n");
        writer.flush();
    }

    private static int getMod(int a, int b) {
        return (a % b + b) % b;
    }
}
